#include "pool.h"
#include <stdio.h>
#include <boost/bind.hpp>
#include <string>
using std::string;
void func1()
{
    printf("task1 running.\n");
    sleep(1);
    printf("task1 waked.\n");
}
void func2(int arg)
{
    printf("task2 arg is %d.\n",arg);
    ++arg;
    printf("task2 arg now is %d.\n",arg);
}
void func3(int arg1,int arg2)
{
    printf("task3 arg1+arg2=%d.\n",arg1+arg2);
    arg1++;
    arg2++;
    sleep(1);
    printf("task3 arg1+arg2=%d.\n",arg1+arg2);
}
void func4(const string& str)
{
    printf("task4 %s\n",str.c_str());
}
int main()
{
    printf("main in thread: %lu.\n",(unsigned long)pthread_self());
    threadpool::task_type task1 = boost::bind(func1);
    threadpool::init_thread_pool();
    threadpool::queue_work_task(task1,0);
    task1 = boost::bind(func2,10);
    int id = threadpool::queue_timer_task(task1,1,false);
    threadpool::queue_work_task(boost::bind(func3,4,5),0);
    threadpool::queue_timer_task(boost::bind(func4,"1234567"),3,true);
    sleep(10);
    threadpool::queue_work_task(task1,0);
    threadpool::queue_timer_task(boost::bind(func4,"1234567"),2,true);
    threadpool::queue_work_task(boost::bind(func3,4,5),0);
    threadpool::queue_timer_task(boost::bind(func4,"1234567"),3,true);
    threadpool::queue_work_task(task1,0);
    id = threadpool::queue_timer_task(task1,1,false);
    threadpool::queue_timer_task(boost::bind(func4,"12345677654321"),3,true);
    sleep(20);
    threadpool::destroy_thread_pool();
    printf("leave thread pool.\n");
}
